/**
 * 
 */
package chess;

import java.util.ArrayList;


/**
 * 
 * The basic definition of a chess piece
 * 
 * @author Max Joyce (Jan 21,2010)
 *
 */
public abstract class Piece {

	protected Player player;             //The player that owns this piece
	
	protected ArrayList<Tile> movementTiles;  //This should be all Tiles that the piece could move to
									          //if he was the only piece left
	
	private boolean moved;
	protected Tile currentTile;
	
	/**
	 * 
	 * Generates a new piece
	 * 
	 * <pre>
	 * Max Joyce 
	 * -Made the method (Jan 21,2010)
	 * -Pulled attackTiles up to the ChessGame class rather than in Piece (Jan 24, 2010)
	 * </pre>
	 * @param p The player that this piece belongs to
	 * @param t The tile that this piece is sitting on
	 */
	public Piece(Player p,Tile t) {
		currentTile = t;
		// TODO Auto-generated constructor stub
		movementTiles = new ArrayList<Tile>();
		player = p;
		p.getMyPieces().add(this);
		moved =false;
	}
	

	/**
	 * Tile is null if dead
	 * <pre>
	 * Max Joyce 
	 * -Made the method (Jan 21,2010)
	 * </pre>
	 * @return Returns true if the piece is dead, false if not
	 */
	 public boolean isDead(){
		 if (currentTile==null){
			 return true;
		 }
		 return false;
	 }
	 
	 /**
	  * This function finds the list of all possible movement locations that the piece could move
	  * to if the board
	  * <pre>
	  * Max Joyce
	  * -Made method signature (Jan 22,2010)
	  * </pre>
	  * @return Returns the list of tiles that could be moved to if the board was empty
	  */
	 public abstract ArrayList<Tile> getMovementTiles();
	 
	 public abstract String getName();
	 
	 /**
	  * This function kills the piece by setting his tile to null
	  * * <pre>
	  * Samual Martelli
	  * -Made method die for piece (Jan 22,2010)
	  * Max Joyce
	  * -Added to die, so that it sets the pieces tile to null (Jan 24,2010)
	  * </pre>
	  */
	 public void die(){
		 this.currentTile.setPieceHere(null);
		 this.currentTile=null;
	 }
	 
	 
	 /**
	  * This function moves the piece to a new tile
	  * * <pre>
	  * Max Joyce
	  * -Creation (Jan 24,2010)
	  * </pre>
	  */
	 public void move(Tile newLocation){
		 this.currentTile.setPieceHere(null);
		 this.currentTile=newLocation;
		 if (newLocation!=null){
			 this.currentTile.setPieceHere(this); 
		 }
		
	 }


	 /**
	  * This function gets the current tile
	  * * <pre>
	  * Max Joyce
	  * -Creation (Feb 9,2010)
	  * </pre>
	  */
	 public Tile getCurrentTile(){
		 return this.currentTile;
	 }
	 
	 /**
	  * This function gets the current player
	  *  <pre>
	  * Samual Martelli
	  * -Creation (Feb 12,2010)
	  * </pre>
	  */
	 public Player getPlayer(){
		 return this.player;
	 }

	 /**
	  * This function signals that a piece has been moved
	  *  <pre>
	  * Samual Martelli
	  * -commented(March 23,2010)
	  * </pre>
	  */
	 public void setMoved(boolean bMoved){
		 this.moved=bMoved;
	 }
	 
	 /**
	  * This function checks if a piece has been moved
	  *  <pre>
	  * Samual Martelli
	  * -commented(March 23,2010)
	  * </pre>
	  */
	 public boolean hasMoved(){
		 return moved;
	 }

	 /**
	  * This function sets the piece's current tile to the new tile 
	  *  <pre>
	  * Samual Martelli
	  * -commented(March 23,2010)
	  * </pre>
	  */
	public void setCurrentTile(Tile newTile) {
		this.currentTile=newTile;
		
	}


}
